     /********************************************************************************/
    /*************** Firm's Source Country or Project Characteristics? **************/
   /* Survey Experiments on Preferences for Chinese Investment in the Global South */
  /********************************************************************************/
 /****************** David Bulman, Ning Leng, and Kerry Ratigan ******************/
/********************************************************************************/

/* This file should be used with the SourceCountryProjectCharacteristics_CleanData.dta and SourceCountryProjectCharacteristics_ReshapedData.dta files. 
It creates the following output appearing in the published paper: 

Main Text:
--Figure 1 – Main conjoint experiment results
--Figure 2 – Conjoint experiment results, by region 
--Figure 3 – Conjoint experiment project-country interaction effects
--Figure 4 – "Diamond" investment vignette treatment effects on cooperation preferences
--Figure 5 – Chinese project awareness (colocation) and cooperation preferences

Supplemntary Materials
--Figure D1 – Baseline conjoint experiment results, reporting marginal means
--Figure D2 – Conjoint experiment results by region, reporting marginal means
--Figure D3a-j, Conjoint experiment results, by country
--Figure D4a-g, Conjoint experiment results, stratified by specified sub-population 
--Figure D5 – Conjoint experiment project-country interaction effects, reporting marginal means
--Figure F1 – "Diamond" investment vignette treatment effects on cooperation preferences, including control variables
*/

local countries="Kenya Nigeria SouthAfrica Argentina Brazil Colombia Peru Indonesia Malaysia Philippines "

/* TEST #1 */

use SourceCountryProjectCharacteristics_ReshapedData.dta, clear

*Figure 1. Baseline
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, id(responseid) est(amce) graph(0)
	graph save Figure1.gph, replace

*Figure 2. Conjoint Results, By Region, AMCE
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(region)
	graph save Figure2.gph, replace 
	
*Appendix Figure D1.  Baseline Conjoint Results, Marginal Means
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, id(responseid) est(mm) graph(0)
	graph save FigureD1.gph, replace

*Appendix Figure D2.  Conjoint Results, By Region, Marginal Means
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(mm) id(responseid) graph(0) subgroup(region)
	graph save FigureD2.gph, replace 	
	
*Appendix Figure D3a-D3j: Conjoint Results, By Country, AMCE
foreach ctry in `countries' {
	conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption if country=="`ctry'", est(amce) id(responseid) graph(0)
		graph save FigureD3_`ctry'.gph, replace
	}
		
*Appendix Figure D4Aa-x: Conjoint Results, By Sub-Population, AMCE
gen age=d_age
replace age=3 if age==4
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(age)
	graph save FigureD4a_Age.gph, replace 
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(d_female)
	graph save FigureD4b_Gender.gph, replace 
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(d_college)
	graph save FigureD4c_Education.gph, replace 
gen income=1 if d_income==1 | d_income==2 
replace income=2 if d_income==3 | d_income==4
replace income=3 if d_income>5
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(income)
	graph save FigureD4d_Income.gph, replace
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(d_urban)
	graph save FigureD4e_Urban.gph, replace 
gen ideology=2 if c_ideology_1!=.
replace ideology=1 if c_ideology_1<5 
replace ideology=3 if c_ideology_1>7
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(ideology)
	graph save FigureD4f_Ideology.gph, replace 
conjoint selected att_country att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(c_vote_win)
	graph save FigureD4g_PoliticalSupport.gph, replace 


/* TEST #2 */

*Figure 3. Interactions with China attribute, AMCE
preserve
keep if att_country==1 | att_country==2
conjoint selected att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(amce) id(responseid) graph(0) subgroup(att_country)
		graph save Figure3.gph, replace
restore

*Figure A4. Interactions with China attribute, MM
gen att_china=att_country==2
conjoint selected att_sector att_jobs att_migrant att_labor att_environment att_corruption, est(mm) id(responseid) graph(0) subgroup(att_china)
		graph save FigureD5.gph, replace


/* TEST #3 */

/* Analysis of open-ended responses */
use SourceCountryProjectCharacteristics_CleanData.dta, clear

gen open_typea_job = 0
gen open_typea_migrant = 0
gen open_typea_labor = 0
gen open_typea_env = 0
gen open_typea_sector = 0
gen open_typea_corrupt = 0
gen open_typeb_china = 0
gen open_typeb_saudi = 0
gen open_typeb_india = 0
gen open_typeb_usa = 0
gen open_typeb_japan = 0
gen open_typeb_anyctry = 0

replace open_typea_job = 1 if regexm(conjoint_open, "(?i)\b(job|jobs|jbo|empleo|empleos|trabajo|trabajos|trabalho|trabalhos|pekerjaan|kerja|employ|employment|emplear|emprego|worker|workers|工|工作|就业|雇佣)\b")
replace open_typea_migrant = 1 if regexm(conjoint_open, "(?i)\b(migrant|migrants|migrnat|migrante|migrantes|imigrante|imigrantes|migran|foreign worker|foreign workers|trabajador extranjero|trabajadores extranjeros|trabalhador estrangeiro|trabalhadores estrangeiros|pekerja asing|tenaga kerja asing|移民|外籍工人|外来工|外来务工人员)\b")
replace open_typea_labor = 1 if regexm(conjoint_open, "(?i)\b(labor|labour|trabalho|trabalhos|kerja|labour|human rights|derechos humanos|direitos humanos|hak asasi manusia|violation|violations|violación|violaciones|violação|pelanggaran|penyalahgunaan|劳动|人权|权利|侵犯)\b")
replace open_typea_env = 1 if regexm(conjoint_open, "(?i)\b(environment|environmental|medioambiente|meio ambiente|lingkungan|sustainability|sustainable|sostenibilidad|sostenible|sustentabilidade|sustentável|climate|pollute|pollution|contaminación|poluição|polusi|pencemaran|环境|可持续性|气候|污染)\b")
replace open_typea_sector = 1 if regexm(conjoint_open, "(?i)\b(sector|sectors|sektor|mining|solar|grocery|grocer|groceries|minería|minerações|mineração|supermercado|agriculture|agricultura|pertanian|agrikultura|manufacture|manufacturing|fabricación|fabricar|producción|produccion|manufactura|manufatura|pembuatan|perkilangan|pengilangan|部门|行业|农业|制造业|采矿|太阳能|杂货|超市)\b")
replace open_typea_corrupt = 1 if regexm(conjoint_open, "(?i)\b(bribery|briberies|bribe|corrupt|soborno|sobornos|corrupción|suborno|korupsi|rasuah|bribe|politician|贿赂|腐败|贪污|行贿|政治家)\b")
replace open_typeb_china = 1 if regexm(conjoint_open, "(?i)\b(chinese|china|cina|中国|中华|华人)\b")
replace open_typeb_saudi = 1 if regexm(conjoint_open, "(?i)\b(saudi|saudis|saudi arabia|arabia saudita|arábia saudita|arab saudi|السعودية|阿拉伯|沙特)\b")
replace open_typeb_india = 1 if regexm(conjoint_open, "(?i)\b(india|indias|índia|印度)\b")
replace open_typeb_usa = 1 if regexm(conjoint_open, "(?i)\b(usa|america|eeuu|eua|amerika|amerika serikat|united states|estados unidos|美国)\b")
replace open_typeb_japan = 1 if regexm(conjoint_open, "(?i)\b(japan|japón|japão|jepang|jepun|日本)\b")

gen conjoint_typea=0
gen conjoint_typeb=0
gen conjoint_typeb1=0
gen conjoint_typec=0
gen conjoint_typec1=0
gen conjoint_typed=0

replace conjoint_typea=1 if open_typea_job==1 | open_typea_migrant==1 | open_typea_labor==1 |open_typea_env==1 | open_typea_sector==1 
replace conjoint_typeb=1 if open_typeb_china==1 | open_typeb_saudi==1 | open_typeb_india==1 | open_typeb_usa==1 | open_typeb_japan==1 
replace conjoint_typeb1=1 if open_typeb_china==1 
replace conjoint_typec=1 if conjoint_typea==1 & conjoint_typeb==1
replace conjoint_typec1=1 if conjoint_typea==1 & conjoint_typeb1==1
replace conjoint_typed=1 if conjoint_typea==0 & conjoint_typeb==0 & conjoint_open!=""


/* TEST #4 */
use SourceCountryProjectCharacteristics_CleanData.dta, clear

gen treat_usa=diamond_usa!=.
	label variable treat_usa "Treatment (US)"
gen treat_chn=diamond_chn!=.
	label variable treat_chn "Treatment (China)"
gen diamond_oppose=0
replace diamond_oppose=1 if diamond_usa==1 | diamond_chn==1

ologit favorable_chn treat_chn i.ctrycode if treat_usa==0
	estimates store favorable_chn
ologit favorable_usa treat_usa  i.ctrycode if treat_chn==0
	estimates store favorable_usa
ologit coop_inv_chn treat_chn i.ctrycode if treat_usa==0
	estimates store inv_chn
ologit coop_inv_usa treat_usa i.ctrycode if treat_chn==0
	estimates store inv_usa
ologit coop_trade_chn treat_chn i.ctrycode if treat_usa==0
	estimates store trade_chn
ologit coop_trade_usa treat_usa i.ctrycode if treat_chn==0
	estimates store trade_usa
ologit coop_mil_chn treat_chn i.ctrycode if treat_usa==0
	estimates store mil_chn
ologit coop_mil_usa treat_usa i.ctrycode if treat_chn==0
	estimates store mil_usa
ologit coop_party_chn treat_chn i.ctrycode if treat_usa==0
	estimates store party_chn
ologit coop_party_usa treat_usa i.ctrycode if treat_chn==0
	estimates store party_usa

coefplot (inv_chn, label("Investment")) ///
		(trade_chn, label("Trade")) ///
		(mil_chn, label("Military")) ///
		(party_chn, label("Party")) ///
		(favorable_chn, label("Favorability")), bylabel("China Diamond treatment") ||  ///
		(inv_usa, label("Investment")) ///
		(trade_usa, label("Trade")) ///
		(mil_usa, label("Military")) ///
		(party_usa, label("Party")) ///
		(favorable_usa, label("Favorability")), bylabel("US Diamond treatment") ||,  ///
	drop(_cons  ?.ctrycode ??.ctrycode) msize(small) ylabel(,labsize(vsmall)) xline(1) eform xtitle(Odds ratio)
graph save Figure4.gph, replace

local controls="d_age d_female d_college d_income"
label variable d_age "Age"
label variable d_female "Female"
label variable d_college "College"
label variable d_income "Income"

ologit favorable_chn treat_chn `controls' i.ctrycode if treat_usa==0
	estimates store favorable_chn
ologit favorable_usa treat_usa `controls' i.ctrycode if treat_chn==0
	estimates store favorable_usa
ologit coop_inv_chn treat_chn `controls' i.ctrycode if treat_usa==0
	estimates store inv_chn
ologit coop_inv_usa treat_usa `controls' i.ctrycode if treat_chn==0
	estimates store inv_usa
ologit coop_trade_chn treat_chn `controls' i.ctrycode if treat_usa==0
	estimates store trade_chn
ologit coop_trade_usa treat_usa `controls' i.ctrycode if treat_chn==0
	estimates store trade_usa
ologit coop_mil_chn treat_chn `controls' i.ctrycode if treat_usa==0
	estimates store mil_chn
ologit coop_mil_usa treat_usa `controls' i.ctrycode if treat_chn==0
	estimates store mil_usa
ologit coop_party_chn treat_chn `controls' i.ctrycode if treat_usa==0
	estimates store party_chn
ologit coop_party_usa treat_usa `controls' i.ctrycode if treat_chn==0
	estimates store party_usa

coefplot (inv_chn, label("Investment")) ///
		(trade_chn, label("Trade")) ///
		(mil_chn, label("Military")) ///
		(party_chn, label("Party")) ///
		(favorable_chn, label("Favorability")), bylabel("China Diamond treatment") ||  ///
		(inv_usa, label("Investment")) ///
		(trade_usa, label("Trade")) ///
		(mil_usa, label("Military")) ///
		(party_usa, label("Party")) ///
		(favorable_usa, label("Favorability")), bylabel("US Diamond treatment") ||,  ///
	drop(_cons ?.ctrycode ??.ctrycode) msize(small) ylabel(,labsize(vsmall)) xline(1) eform xtitle(Odds ratio) order(treat_chn treat_usa)
graph save FigureF1.gph, replace


/* TEST #5 */

label variable c_project "Chinese project awareness"
local controls=""

ologit favorable_chn c_project `controls' i.ctrycode if treat_usa==0 & treat_chn==0
	estimates store favorable_chn2
ologit coop_inv_chn c_project `controls' i.ctrycode if treat_usa==0 & treat_chn==0
	estimates store inv_chn2
ologit coop_trade_chn c_project `controls' i.ctrycode if treat_usa==0 & treat_chn==0
	estimates store trade_chn2
ologit coop_mil_chn c_project `controls' i.ctrycode if treat_usa==0 & treat_chn==0
	estimates store mil_chn2
ologit coop_party_chn c_project `controls' i.ctrycode if treat_usa==0 & treat_chn==0
	estimates store party_chn2


coefplot (inv_chn2, label("Investment")) ///
		(trade_chn2, label("Trade")) ///
		(party_chn2, label("Party")) ///
		(mil_chn2, label("Military")) ///
		(favorable_chn2, label("Favorability")), ///
	drop(_cons ?.ctrycode ??.ctrycode) xline(1) msize(small) ylabel(,labsize(vsmall)) eform xtitle(Odds ratio)
graph save Figure5.gph, replace


